/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2019年3月30日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.lesson3.sort;

import java.util.Arrays;

import test.lesson3.MyQueue;

/**
 * @Type RadixSortQueue
 * @Desc
 * @author 52489
 * @date 2019年3月30日
 * @Version V1.0
 */
public class RadixSortQueue {

    public static void sortByQueue(int nums[]) {

        MyQueue queue = new MyQueue();

        int max = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] > max) {
                max = nums[i];
            }
        }

        int weishu = (max + "").length();

        for (int i = 1; i <= weishu; i++) {
            System.out.println("第" + i + "位排序");
            for (int k = 0; k < 10; k++) {
                System.out.println("数字" + k + ":   ");
                for (int j = 0; j < nums.length; j++) {
                    String numStr = nums[j] + "";
                    if (numStr.length() < i) {
                        if (k == 0) {
                            queue.add(nums[j]);
                            System.out.println("位数数字0" + "_" + nums[j]);
                        }

                    } else {
                        char x = numStr.charAt(numStr.length() - i);
                        int weishuNum = Integer.parseInt(String.valueOf(x));
                        if (k == weishuNum) {
                            System.out.println("位数数字" + x + "_" + nums[j]);
                            queue.add(nums[j]);
                        }
                    }
                }
            }
            int tmp[] = new int[nums.length];
            for (int j = 0; j < tmp.length; j++) {
                tmp[j] = queue.poll();
            }
            nums = tmp.clone();
            tmp = new int[nums.length];
            System.out.println(Arrays.toString(nums));
            System.out.println("\n");
        }

    }

    public static void main(String[] args) {
        int nums[] = { 12, 4, 531, 31, 66, 14, 125, 1, 43, 54 };
        sortByQueue(nums);
    }

}
